Format balance and est. cost values in trading widget#791
Merged
realproject7 merged 2 commits intomainfrom Apr 3, 2026
Merged
Conversation
Add formatTokenAmount() helper with precision rules: - >= 1: 2 decimals with thousands separators (e.g. 5,034.43) - >= 0.001: 4 decimals (e.g. 0.0033) - < 0.001: 6 decimals (e.g. 0.000001) Applied to all balance displays and estimate cost/return values across ETH, USDC, HUNT, and PLOT modes. Fixes #789 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
project7-interns
requested changes
Apr 3, 2026
Collaborator
project7-interns
left a comment
There was a problem hiding this comment.
Verdict: REQUEST CHANGES
Summary
The helper improves readability for normal values, but it still misformats one class of numbers: tiny non-zero amounts can now render as zero. That is a user-visible correctness issue for balances and estimates.
Findings
- [medium]
formatTokenAmount()rounds every value below0.001withtoFixed(6). For any non-zero amount smaller than0.0000005, that returns0.000000, so the widget shows a real balance / estimate as zero instead of a tiny positive value. The issue explicitly allowed scientific notation here, and the repo already usestoExponential(0)for very small values inlib/format.ts:12.- File:
src/components/TradingWidget.tsx:31 - Suggestion: switch the smallest range to scientific notation (or another non-zero-preserving representation) instead of fixed 6dp once the value falls below the precision floor.
- File:
Decision
Requesting changes because the new formatter can misstate tiny non-zero token amounts as zero.
Values below 0.000001 now use toExponential(2) instead of toFixed(6) to prevent rendering as "0.000000". Consistent with existing toExponential usage in lib/format.ts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
project7-interns
approved these changes
Apr 3, 2026
Collaborator
project7-interns
left a comment
There was a problem hiding this comment.
Verdict: APPROVE
Summary
The formatter now preserves tiny non-zero values instead of collapsing them to zero, while still improving readability for the normal balance and estimate cases. I do not have further review findings on this PR.
Findings
- None.
Decision
Approved on code review.
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
formatTokenAmount()helper toTradingWidget.tsxwith tiered precision:5,034.43)0.0033)0.000001)Before/After
5034.425044895956140455 HUNT→5,034.43 HUNT68.623631443223832041 HUNT→68.62 HUNTTest Plan
Fixes #789
🤖 Generated with Claude Code